$(function () {

    ToggleTabs(".js-notice>a", ".message", "js-show");
    ToggleTabs(".js-file>a", ".filelist", "js-show");
    ToggleTabs(".js-filelist>a", ".notice", "js-show");
    ToggleTabs(".js-team>a", ".teams", "js-show");
    ToggleTabs(".js-notice-daysel>a", ".selnotices", "js-show");
    ToggleTabs(".js-rules>a", ".ruled", "js-show");
    ToggleTabs(".js-checkup>a", ".ckeckup", "js-show");
    ToggleTabs(".js-learn>a", ".learen", "js-show");
    ToggleTabs(".js-tougao>a", ".tougao", "js-show");

    // 选项卡
    function ToggleTabs(id, ele, className) {
        if(ele==".tougao"){
            $(id).on("mouseover", function () {
                var now = $(this).index() - 1;
                $(this).addClass("js-news-title").siblings().removeClass("js-news-title");
                $(ele).eq(now).addClass(className).siblings().removeClass(className)
            })
        }else{
            $(id).on("click", function () {
                var now = $(this).index() - 1;
                $(this).addClass("js-news-title").siblings().removeClass("js-news-title");
                $(ele).eq(now).addClass(className).siblings().removeClass(className)
            })
        }

    }

    // 获取时间
    var dayArr = ["日", "一", "二", "三", "四", "五", "六"];

    setInterval(function () {
        var date = new Date();
        var y = date.getFullYear();
        var m = date.getMonth() + 1;
        var d = date.getDate();
        var h = date.getHours();
        var min = date.getMinutes();
        var s = date.getSeconds();
        var week = date.getDay();
        var day = "星期" + dayArr[week];

        $(".time").html("<i class='layui-icon layui-icon-log'></i>&nbsp;" + y + "年" + m + "月" + d + "日 &emsp;" + day);
    }, 1000);


    // 文字滚动
    // $('.inline_notice').marquee({
    //     duration: 10000
    // });

    layui.use(['form','layer', "carousel"], function(){
        var layer = layui.layer;
        var carousel = layui.carousel;
        var form = layui.form;
        // 弹窗------------
        //--------------
        $(".showqs_win").click(function(){
            var newsid=parseInt($(this).attr('id'));
            var newstitle=$(this).attr('title');
            //alert("newsid:"+newsid);
            layer.open({
                title: "签到情况："+newstitle,
                type: 2,
                area: ["660px", "400px"],
                content: showqs_url+"?id="+newsid
            });

        });
        $(".sign_for_click").click(function () {

            layer.open({
                title: "签到情况："+title,
                type: 1,
                area: ["660px", "auto"],
                content: $('.model_content')
            });
        });
        $(".login_win_button").click(function () {
            layer.open({
                title: false,
                type: 1,
                area: ["360px", "auto"],
                content: $('.login_win')
            });
        });

        form.on('submit(*)', function(data){
            //layer.msg(JSON.stringify(data.field));
            //return false;
             /* console.log(data.elem) ;//被执行事件的元素DOM对象，一般为button对象
             console.log(data.form) ;//被执行提交的form对象，一般在存在form标签时才会返回
             console.log(data.field); //当前容器的全部表单字段，名值对形式：{name: value}
            return false;
            layui.$.post(login_url,data.field,function(res){
                if(res.status==1){
                    layer.msg(res.msg,{icon:1,time:1000});
                    setTimeout(function () {
                        var index = layer.getFrameIndex(window.name);
                        location.reload();
                        layer.close(index);
                    }, 1100);
                }else{
                    layer.msg(res.msg,{icon:2,time:1000});
                    //layer.msg('error!'+XmlHttpRequest.responseText+errorThrown,{icon:2,time:1000,area: '1200px'});
                }
            });*/
            return false;
        });

        carousel.render({
            elem: '#header-carousel'
            ,width: '100%' //设置容器宽度
            ,arrow: 'none' //始终显示箭头
            ,anim: 'fade' //切换动画方式
            ,autoplay: true
            ,indicator: "none"
            ,interval: 5000
        });
    });

    $("#loginBtn").click(function(){
        $.ajax({
            type: 'post',
            url: login_url ,
            data:{username:$("#username").val(),password:$("#password").val()},
            success: function(data){
                if(data.status==1){
                    layer.msg(data.msg,{icon:1,time:1000});
                    setTimeout(function () {
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.location.reload();
                        parent.layer.close(index);
                    }, 1100);
                }else{
                    layer.msg(data.msg+"-提交失败！",{icon:2,time:1000});
                }

            },
            error: function(XmlHttpRequest, textStatus, errorThrown){
                layer.msg('error!',{icon:2,time:1000});
                //layer.msg('error!'+XmlHttpRequest.responseText+errorThrown,{icon:2,time:1000,area: '1200px'});
            }
        });
    });
    $(".doqs").click(function(){
        $.ajax({
            type: 'post',
            url: doqs_url ,
            data:{id:id,userid:userid},
            success: function(data){
                if(data.status==1){
                    layer.msg(data.msg,{icon:1,time:1000});
                    setTimeout(function () {
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.location.reload();
                        parent.layer.close(index);
                    }, 1100);
                }else{
                    layer.msg(data.msg+"-提交失败！",{icon:2,time:1000});
                }

            },
            error: function(XmlHttpRequest, textStatus, errorThrown){
                layer.msg('error!',{icon:2,time:1000});
                //layer.msg('error!'+XmlHttpRequest.responseText+errorThrown,{icon:2,time:1000,area: '1200px'});
            }
        });
    });
    $(".doqs_index").click(function(){
        var id=parseInt($(this).attr('id'));
        $.ajax({
            type: 'post',
            url: doqs_url ,
            data:{id:id,userid:userid},
            success: function(data){
                if(data.status==1){
                    layer.msg(data.msg,{icon:1,time:1000});
                    setTimeout(function () {
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.location.reload();
                        parent.layer.close(index);
                    }, 1100);
                }else{
                    layer.msg(data.msg,{icon:2,time:1000});//+"[提交失败]！"
                }

            },
            error: function(XmlHttpRequest, textStatus, errorThrown){
                layer.msg('error!',{icon:2,time:1000});
                //layer.msg('error!'+XmlHttpRequest.responseText+errorThrown,{icon:2,time:1000,area: '1200px'});
            }
        });
    });
    $(".layui-icon-search").click(function(){
       // alert($("#keyword").val());
        $.ajax({
            type: 'post',
            url: news_url ,
            data:{keyword:$("#keyword").val()},
            success: function(){
                window.location.href=news_url+"?keyword="+$("#keyword").val();
                /*if(data.status==1){
                    layer.msg(data.msg,{icon:1,time:1000});
                    setTimeout(function () {

                    }, 1100);
                }else{
                    layer.msg(data.msg+"-提交失败！",{icon:2,time:1000});
                }*/

            },
            error: function(XmlHttpRequest, textStatus, errorThrown){
                layer.msg('error!',{icon:2,time:1000});
                //layer.msg('error!'+XmlHttpRequest.responseText+errorThrown,{icon:2,time:1000,area: '1200px'});
            }
        });
    });

    var mySwiper = new Swiper('.swiper-header-news',{
        autoplay : 3000,
        pagination: '.pagination',
        loop:true,
        grabCursor: true,
        paginationClickable: true
    });
    $('.swiper-prev').on('click', function(e){
        e.preventDefault();
        mySwiper.swipePrev()
    });
    $('.swiper-next').on('click', function(e){
        e.preventDefault();
        mySwiper.swipeNext()
    });

    var swiper = new Swiper('.footer-swiper', {
        autoplay : 3000,
        pagination: '.pagination',
        paginationClickable: true,
        slidesPerView: 4,
        spaceBetween: 34,
        freeMode: true,
        loop:true,
    });
    $('.swiper-footer-prev').on('click', function(e){
        e.preventDefault();
        swiper.swipePrev()
    });
    $('.swiper-footer-next').on('click', function(e){
        e.preventDefault();
        swiper.swipeNext()
    });
});
